from sklearn.tree import DecisionTreeClassifier
from sklearn.preprocessing import OrdinalEncoder
import pandas as pd

# 数据
data = [
    ["晴朗", "午餐", "好", "高", "日料"],
    ["下雨", "晚餐", "差", "低", "快餐"],
    ["阴天", "午餐", "一般", "中", "中餐"],
    ["下雨", "晚餐", "好", "高", "西餐"],
    ["晴朗", "午餐", "差", "低", "快餐"],
    ["阴天", "晚餐", "好", "中", "西餐"],
    ["下雨", "午餐", "一般", "高", "日料"],
    ["晴朗", "晚餐", "好", "中", "中餐"],
    ["阴天", "晚餐", "差", "低", "快餐"],
    ["下雨", "午餐", "好", "高", "日料"],
]

df = pd.DataFrame(data, columns=["天气", "时间", "心情", "预算", "点的外卖"])

# 编码
oe = OrdinalEncoder()
X = oe.fit_transform(df.iloc[:, :-1])
y = df["点的外卖"]

# 构建模型
clf = DecisionTreeClassifier(criterion="entropy", max_depth=3)
clf.fit(X, y)

# 预测新数据：天气=阴天，时间=晚餐，心情=好，预算=高
new_data = [["阴天", "晚餐", "好", "高"]]
new_data_encoded = oe.transform(new_data)
print("预测外卖：", clf.predict(new_data_encoded)[0])
